[WRONG BRANCH] bound: limit Codex WS upstream frame and queued-response bytes to prevent OOM - #266
[WRONG BRANCH] bound: limit Codex WS upstream frame and queued-response bytes to prevent OOM#266luvs01 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe WebSocket response stream now enforces 4 MiB frame and 8 MiB queue limits. It encodes SSE output into byte buffers, rejects limit violations, errors the stream, and closes the WebSocket. Tests cover frame rejection and queue overflow. ChangesWebSocket stream limits
Estimated code review effort: 3 (Moderate) | ~20 minutes Mergeability Score: ⚪ Minimal · up to The change bounds upstream WebSocket frame and queued-response memory usage while preserving the existing flow, with regression tests and repository checks reported as passing; no actionable merge-blocking risk remains. Sequence Diagram(s)sequenceDiagram
participant UpstreamWebSocket
participant ResponseReadableStream
participant SSEByteBuffer
UpstreamWebSocket->>ResponseReadableStream: receive upstream frame
ResponseReadableStream->>SSEByteBuffer: encode accepted SSE event
SSEByteBuffer->>ResponseReadableStream: enqueue bytes within queue limit
ResponseReadableStream->>UpstreamWebSocket: fail stream and close on limit violation
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Its title has been prefixed with |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 97ef99dc54
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const availableBytes = controller.desiredSize ?? 0; | ||
| if (frameBytes > availableBytes) { |
There was a problem hiding this comment.
Bound buffering after the production tee
On the default non-Windows passthrough route, src/server/responses/core.ts:2639-2695 tees this body and continuously drains the inspection branch even when the client branch is stalled. Because a tee pulls whenever either branch wants data, that drain replenishes desiredSize here while the unread bytes accumulate without a byte limit in nativeBody; a slow client combined with a rapidly emitting upstream can therefore still grow memory until OOM without triggering this check. Apply the byte budget after the tee, or route this transport through the single-reader bounded relay, and cover the production passthrough path rather than only reading the returned Response directly.
Useful? React with 👍 / 👎.
|
@coderabbitai review |
✅ Action performedReview finished.
|
Motivation
Description
MAX_CODEX_WS_FRAME_BYTES(4 MiB) andMAX_CODEX_WS_QUEUE_BYTES(8 MiB) and usingByteLengthQueuingStrategyfor the returnedReadableStreamso buffered bytes are bounded.controller.desiredSizebefore enqueueing an SSE-encoded frame and close the socket with an error when the buffered queue would be exceeded via afailStreamhelper that errors the stream and closes the socket.tests/ws-upstream.test.tsthat assert oversized frames are rejected and that an upstream producing enough data to fill the bounded queue is disconnected, plus expose the new constants for testing and assertions.Testing
bun test tests/ws-upstream.test.ts -t 'rejects an oversized|disconnects an upstream', which passed.bun run typecheckand the full test suite withbun run test, both of which passed in the repository test runner environment; the environment-local singlebun test tests/ws-upstream.test.tsrun initially hit unrelated runtime differences in the external Bun binary (timer API andnode:zlibzstd symbol) but the repository's test runner executed the full suite successfully.bun run privacy:scanwhich returned clean/green for the changes.Codex Task
Summary by CodeRabbit
Bug Fixes
Performance
Tests